﻿@using QDT.Core
@using QDT.Core.Deals
@using QDT.Core.Projects
@using QDT.MVC.UI
@model QDT.Common.IPagedList<Credit>
@{
    ViewBag.Title = "我的债权";
}
<script src="@Url.Content("~/Content/Default/JS/change.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/Default/CSS/CreditList.css")" rel="stylesheet" type="text/css" />

@Html.Action("_UserBanner")
<div class="ui-body">
    <div class="ui-inner">
        <div class="ui-grid-row">
            @Html.Action("UserMenu", new { route = MenuRoute.CreditAssignment })
            <div class="ui-grid-20">
                <div class="ui-box">
                    @Html.Partial("_CreditAssignment")
                    <div class="ui-table-container" style="height: 491px;">
                        <table style="width: 100%">
                            <thead>
                                <tr>
                                    <th style="padding-left: 50px;">
                                        项目信息
                                    </th>
                                    <th class="th-center">
                                        持有期限
                                    </th>
                                    <th class="th-center">
                                        债权
                                    </th>
                                    <th class="th-center">
                                        已发利息
                                    </th>
                                    <th class="th-center">
                                        选择
                                    </th>
                                </tr>
                            </thead>
                            <tbody id="datalist">
                                @foreach (Credit m in Model)
                                {
                                    Project project = Html.F().GetProject(m.ProjectID);
                                    <tr>
                                        <td class="td-first">
                                            <span><a href="@Url.Action("Index", "Project", new { id = project.ID })" style="text-decoration: underline;font-size: 14px;">@project.Name</a></span>
                                            <div style="line-height: 20px; color: #9d9d9d;">
                                                <span>预期年化收益率：</span><span>@project.Rate<span>%</span></span> &nbsp;&nbsp;<span>期限：</span><span><span>@project.RepayTime</span>个月</span><br />
                                                <span>投标时间：</span>@project.CreateTime<span></span> </div>
                                        </td>
                                        <td class="td-all">
                                            @m.CurrentStage / @m.TotalStage
                                        </td>
                                        <td class="td-all">
                                            @m.Money.ToMoney()
                                        </td>
                                        <td class="td-color">
                                            @m.RepayEarning.ToMoney()
                                        </td>
                                        <td class="td-all">
                                            <input type="radio" id="@("Credit_" + m.ID)" name="Credit_Radio" value="@m.ID" class="radio-hide"/>
                                            <label for="@("Credit_" + m.ID)">
                                                <i name="credit_item" id="@("credit_item_" + m.ID)" class="iconfont">&#xf0035;</i>
                                            </label>
                                        </td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>
                    <div style="text-align: center;">@Html.ClientPager(Model)</div>
                    <div class="ui-wxtx">
                        <span style="font-size: 18px;">温馨提醒</span><br />
                        本次赎回会产生转卖债权额度0.5%的手续费。<br />
                        您设定的折让率越高，您的赎回就会越快成功。到目前为止，全部赎回都在1个工作日内结束。
                        <a href="javascript:;" id="submit_redeem" class="ui-button ui-button-red big" onclick="redeemcredit();" style="margin-left: 30px;">
                            确认赎回
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="ui-layer" id="dialog_assignment_preview">
    <div class="lymask">
    </div>
    <table class="lytable">
        <tbody>
            <tr>
                <td class="lytd">
                    <div class="lywrap">
                        <div class="lytt">
                            <h2 class="u-tt">申请赎回</h2>
                            <a href="javascript:void(0)" onclick=" closeCredit() ">
                                <span class="lyclose">×</span>
                            </a>
                        </div>
                        <div class="lyct" id="assignment_form_preview">
                            
                        </div>
                        <div class="lybt">
                            <div class="lybtns">
                                <button type="button" id="preview_assignment_button" onclick="submit_redeemcredit()" class="ui-button ui-button-red big">确认赎回</button>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>

<div class="ui-layer" id="dialog_assignment">
    <div class="lymask">
    </div>
    <table class="lytable">
        <tbody>
            <tr>
                <td class="lytd">
                    <div class="lywrap">
                        <div class="lytt">
                            <h2 class="u-tt">申请赎回</h2>
                            <a href="javascript:void(0)" onclick=" closeCredit() ">
                                <span class="lyclose">×</span>
                            </a>
                        </div>
                        <div class="lyct" id="assignment_form">
                        </div>
                        <div class="lybt">
                            <div class="lybtns">
                                <button type="button" id="submit_assignment_button" class="ui-button ui-button-red big">确认赎回</button>
                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>

<div style="margin-top: -10px;">
    @Html.Partial("_BindBottomImage")
</div>

<script type="text/javascript">
    $(function () {
        $('[name="Credit_Radio"]').click(function () {
            $('[name="credit_item"]').html('&#xf0035;');
            $('#credit_item_' + $(this).val()).html('&#xf0036;');
        });
    });
    $().ready(function () {
        $("#ui-kezhuanrang a").addClass("a_class");
        $("#CreditAssignment").css("background", "#e0524b");
        $("#CreditAssignment i,#CreditAssignment span").css("color", "white");
        $("#CreditAssignment .san-jiaoxing").css("display", "block");
    });

    function redeemcredit() {
        var cid = $('input[name="Credit_Radio"]:checked').val();
        if (cid == "" || cid == undefined) {
            alert('请先选择需要赎回的债权！');
            return;
        }
        var url = '@Url.Action("AssignForm", "Assignment")' + '?cid=' + cid;

        $('#dialog_assignment_preview #assignment_form_preview').load(url);

        $('#dialog_assignment_preview').addClass("ui-layer-show");

        $.ajax({
            url: url,
            type: 'POST',
            dataType: "json",
            success: function (obj) {
                if (obj.Status == true) {
                    $('#dialog_assignment_preview #assignment_form_preview').html(obj.Data);
                } else {
                    $('#dialog_assignment_preview #assignment_form_preview').html(obj.Info);
                }
            }
        });
    }

    function submit_redeemcredit() {
        var cid = $('input[name="Credit_Radio"]:checked').val();
        if (cid == "" || cid == undefined) {
            alert('请先选择需要赎回的债权！');
            return;
        }
        var disRate = $('#assign_discount_rate').val();
        var money = $('#assign_money').val();
        var url = '@Url.Action("Preview", "Assignment")' + '?cid=' + cid + '&money=' + money + '&discount=' + disRate;

        $('#dialog_assignment #assignment_form').load(url);

        $('#dialog_assignment_preview').removeClass("ui-layer-show");
        $('#dialog_assignment').addClass("ui-layer-show");

        $.ajax({
            url: url,
            type: 'POST',
            dataType: "json",
            success: function (obj) {
                if (obj.Status == true) {
                    $('#dialog_assignment #assignment_form').html(obj.Data);
                } else {
                    $('#dialog_assignment #assignment_form').html(obj.Info);
                }
            }
        });
    }

    function closeCredit() {
        $('#dialog_assignment').removeClass("ui-layer-show");
        $('#dialog_assignment_preview').removeClass("ui-layer-show");
    }

    $('#submit_assignment_button').click(function () {
        $('#dialog_assignment').removeClass("ui-layer-show");
        $('#submit_assignment_form').submit();
    });

</script>
